package com.ruoyi.client.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.client.domain.SysMedicalType;
import com.ruoyi.client.service.ISysMedicalTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 器械类别 Controller
 * 
 * @author ruoyi
 * @date 2022-09-14
 */
@RestController
@RequestMapping("/system/type")
public class SysMedicalTypeController extends BaseController
{
    @Autowired
    private ISysMedicalTypeService sysMedicalTypeService;

    /**
     * 查询器械类别 列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysMedicalType sysMedicalType)
    {
        startPage();
        List<SysMedicalType> list = sysMedicalTypeService.selectSysMedicalTypeList(sysMedicalType);
        return getDataTable(list);
    }

    /**
     * 导出器械类别 列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "器械类别 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysMedicalType sysMedicalType)
    {
        List<SysMedicalType> list = sysMedicalTypeService.selectSysMedicalTypeList(sysMedicalType);
        ExcelUtil<SysMedicalType> util = new ExcelUtil<SysMedicalType>(SysMedicalType.class);
        util.exportExcel(response, list, "器械类别 数据");
    }

    /**
     * 获取器械类别 详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{medTypeId}")
    public AjaxResult getInfo(@PathVariable("medTypeId") Long medTypeId)
    {
        return AjaxResult.success(sysMedicalTypeService.selectSysMedicalTypeByMedTypeId(medTypeId));
    }

    /**
     * 新增器械类别 
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "器械类别 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMedicalType sysMedicalType)
    {
        return toAjax(sysMedicalTypeService.insertSysMedicalType(sysMedicalType));
    }

    /**
     * 修改器械类别 
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "器械类别 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMedicalType sysMedicalType)
    {
        return toAjax(sysMedicalTypeService.updateSysMedicalType(sysMedicalType));
    }

    /**
     * 删除器械类别 
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "器械类别 ", businessType = BusinessType.DELETE)
	@DeleteMapping("/{medTypeIds}")
    public AjaxResult remove(@PathVariable Long[] medTypeIds)
    {
        return toAjax(sysMedicalTypeService.deleteSysMedicalTypeByMedTypeIds(medTypeIds));
    }
}
